package com.nvn.washiodriver.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;

import com.nvn.washiodriver.R;
import com.parse.ParseUser;

public class SplashActivity extends Activity {
	private boolean cancel = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_splash);

		initView();
	}


	private void initView() {

		new CountDownTimer(2000, 1000) {

			@Override
			public void onTick(long millisUntilFinished) {

			}

			@Override
			public void onFinish() {
				if (!cancel) {
					Intent i = new Intent();
					if (ParseUser.getCurrentUser().getObjectId() != null
							&& ParseUser.getCurrentUser().getEmail() != null) {
						i.setClass(SplashActivity.this, MainActivity.class);
					} else {
						i.setClass(SplashActivity.this, LoginActivity.class);
					}

					startActivity(i);
					finish();
				}

			}
		}.start();
	}

	@Override
	public void onBackPressed() {
		cancel = true;
		super.onBackPressed();
	}

}
